home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Games of Daze
/
Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso
/
x2ftp
/
msdos
/
math
/
nrpas13
/
rtnewt.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1991-04-29
|
744b
|
27 lines
FUNCTION rtnewt(x1,x2,xacc: real): real;
(* Programs using routine RTNEWT must externally define procedure
funcd(x,f,df:real) which returns the function value f and its
derivative df at the point x. *)
LABEL 99;
CONST
jmax=20;
VAR
df,dx,f,rtn: real;
j: integer;
BEGIN
rtn := 0.5*(x1+x2);
FOR j := 1 TO jmax DO BEGIN
funcd(rtn,f,df);
dx := f/df;
rtn := rtn-dx;
IF ((x1-rtn)*(rtn-x2) < 0.0) THEN BEGIN
writeln('pause in routine RTNEWT');
writeln('jumped out of brackets'); readln
END;
IF (abs(dx) < xacc) THEN GOTO 99
END;
writeln('pause in routine RTNEWT');
writeln('maximum number of iterations exceeded'); readln;
99: rtnewt := rtn
END;